//
//  SE_Find_View.m
//  SkyEye
//
//  Created by dllo on 16/8/9.
//  Copyright © 2016年 SE. All rights reserved.
//

#import "SE_Find_View.h"
#import "SE_Top_TableViewCell.h"
#import "SE_View_TableViewCell.h"
#import "SE_Square_TableViewCell.h"

#import "SDCycleScrollView.h"
@interface SE_Find_View()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic, retain) UITableView *tableView;
@property (nonatomic, retain) SDCycleScrollView *headScrollView;

@end

@implementation SE_Find_View

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createTableView];
    }
    return self;
}

-(void)createTableView{
    self.tableView = [[UITableView alloc]initWithFrame:self.bounds style:UITableViewStylePlain];
    [self addSubview:self.tableView];
    self.tableView.bounces = NO;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    
    UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 414, 200)];
    headView.backgroundColor = [ UIColor redColor];
    self.tableView.tableHeaderView = headView;
    
    self.headScrollView = [[SDCycleScrollView alloc] initWithFrame:CGRectMake(0, 0, 414, 200)];
    [headView addSubview:_headScrollView];
    [self.tableView registerClass:[SE_Top_TableViewCell class] forCellReuseIdentifier:@"topCell"];
    [self.tableView registerClass:[SE_View_TableViewCell class] forCellReuseIdentifier:@"viewCell"];
    [self.tableView registerClass:[SE_Square_TableViewCell class] forCellReuseIdentifier:@"squareCell"];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 3;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
   
    if (indexPath.row == 0){
        SE_Top_TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"topCell"];
        cell.squareArray = self.squareArray;
        return cell;
    } else if(indexPath.row == 1){
        SE_View_TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"viewCell"];
        cell.viewModel = self.viewArray.firstObject;
        return cell;
    }else{
        SE_Square_TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"squareCell"];
        cell.squareArray = self.squareArray;
        return cell;
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
   
    if(indexPath.row == 0){
        return 210;
    } else if (indexPath.row == 1){
        return 200;
    } else {
        return ([UIScreen mainScreen].bounds.size.width - 10) / 2 * 6 + 39;
    }
}

-(void)setSquareArray:(NSArray *)squareArray{
    _squareArray = squareArray;
    [self.tableView reloadData];
}

-(void)setBannerArray:(NSArray *)bannerArray{
    _bannerArray = bannerArray;
  
    self.headScrollView.imageURLStringsGroup = bannerArray;
    [self.tableView reloadData];
}

-(void)setViewArray:(NSArray *)viewArray{
    _viewArray = viewArray;
    [self.tableView reloadData];
}

@end

















